package com.guigu.buy.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.buy.pojo.ProductType;
import com.guigu.buy.service.IProductTypeService;
import com.guigu.buy.vo.ProductTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/buy/productType")
public class ProductTypeController {
    @Autowired
    private IProductTypeService productTypeService;

    /**
     * 主页获取下拉框的值下拉框
     * @return
     */
    @RequestMapping("/getProType")
    @ResponseBody
    public List<ProductType>list(){
        int parentId=0;
        List<ProductType>list=productTypeService.getProductType(parentId);
        return list;
    }
    /**
     * 删除商品类型
     * @return
     */
    @RequestMapping("/delOne/{id}")
    @ResponseBody
    public Boolean delOne(@PathVariable int id){

        return productTypeService.delOne(id);
    }
    //查询所有商品类型
    @RequestMapping("/queryAll/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<ProductType> queryAll(@PathVariable int pageSize,
                                         @PathVariable int pageNo,
                                         @RequestBody ProductTypeVo vo){
        return productTypeService.selectAll(pageNo,pageSize,vo);
    }
    //修改商品类型
    @RequestMapping("/upProductType/{id}")
    @ResponseBody
    public ProductType upProductType(@PathVariable int id){

        ProductType productType=productTypeService.getById(id);
        return productType;
    }
    //修改商品类型2
    @RequestMapping("/upProductType2")
    @ResponseBody
    public Boolean upProductType2(@RequestBody ProductType productType1){
        ProductType productType=new ProductType();
        productType.setProductTypeName(productType1.getProductTypeName());
        productType.setProductTypeStatus(productType1.getProductTypeStatus());
        productType.setId(productType1.getId());
        Boolean f=productTypeService.updateById(productType);
        return f;
    }
    //添加商品类型
    @RequestMapping("/addProductType2")
    @ResponseBody
    public Boolean addProductType2(@RequestBody ProductType productType1){
        ProductType productType=new ProductType();
        productType.setProductTypeName(productType1.getProductTypeName());
        productType.setParentId(productType1.getParentId());
        productType.setLevel(productType1.getLevel());
        productType.setProductTypeStatus(productType1.getProductTypeStatus());
        productType.setId(null);
        productType.setCreateTime(new Date());
        productType.setUpdateTime(new Date());
        productType.setDeleteStatus("0");
        Boolean f=productTypeService.save(productType);
        return f;
    }
    /**
     * 查询所有商品类型
     * @return
     */
    @RequestMapping("/getProTypeName/{id}")
    @ResponseBody
    public ProductType getProTypeName(@PathVariable int id){
//        QueryWrapper<ProductType> wrapper=new QueryWrapper<>();
//        wrapper.eq("delete_status",0);
        ProductType list=productTypeService.getById(id);
        return list;
    }
}
